local wuyulong = fk.CreateSkill {
  name = "lingling__wuyulong",
}

Fk:loadTranslationTable {
  ["lingling__wuyulong"] = "舞鱼龙",
  [":lingling__wuyulong"] = "出牌阶段限一次或当你受到伤害后，你可以与一名其他角色交换所有手牌，然后手牌较少的一方摸两张牌。",

  ["#lingling__wuyulong"] = "舞鱼龙：与一名角色交换所有手牌，手牌较少的一方摸两张牌。",
  ["#lingling__wuyulong-choose"] = "舞鱼龙：与一名角色交换手牌",

  ["#lingling__luyou_xinqiji_EasterEgg"] = "中原麟凤争自奋，残虏犬羊何足嚇。",
  ["#lingling__luyou_xinqiji_slash"] = "陆游&辛弃疾：你可以视为使用一张【杀】!"
}

local spec = {
  on_use = function(self, room, effect)
    local player = effect.from
    --[[local targets = room:getOtherPlayers(player, false)
    if player:isKongcheng() then
      targets = table.filter(targets, function(p)
        return not p:isKongcheng()
      end)
    end
    if #targets > 0 then
      local to = room:askToChoosePlayers(player, {
        min_num = 1,
        max_num = 1,
        targets = targets,
        skill_name = wuyulong.name,
        prompt = "#lingling__wuyulong-choose",
        cancelable = false,
      })[1]]--
      local to = effect.tos[1]
      room:swapAllCards(player, { player, to }, wuyulong.name)
      if player.dead or to.dead then return end
      if player:getHandcardNum() < to:getHandcardNum() then
        player:drawCards(2, wuyulong.name)
      elseif to:getHandcardNum() < player:getHandcardNum() then
        to:drawCards(2, wuyulong.name)
      end
      --彩蛋效果
      if player.dead then return end
      if player.general == "lingling__xinqiji" and to.general == "lingling__luyou" and
          player:getMark("lingling__luyou_xinqiji_EasterEgg") == 0 then
        room:setPlayerMark(player, "lingling__luyou_xinqiji_EasterEgg", 1)
        room:sendLog {
          type = "#lingling__luyou_xinqiji_EasterEgg",
          from = player.id,
          toast = true,
        }
        room:askToUseVirtualCard(player, {
          name = "slash",
          skill_name = wuyulong.name,
          prompt = "#lingling__luyou_xinqiji_slash",
          cancelable = true,
          extra_data = {
            bypass_times = true,
            extraUse = true,
          },
        })
      end
    --end
  end,
}

wuyulong:addEffect("active", {
  anim_type = "drawcard",
  prompt = "#lingling__wuyulong",
  max_phase_use_time = 1,
  can_use = function(self, player)
    return self:withinTimesLimit(player, Player.HistoryPhase)
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 1,
  target_filter = function (self, player, to_select, selected, selected_cards, card, extra_data)
    return #selected == 0 and player ~= to_select and (not player:isKongcheng() or not to_select:isKongcheng())
  end,
  on_use = spec.on_use,
})

wuyulong:addEffect(fk.Damaged, {
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(wuyulong.name) and target == player
  end,
  on_cost = function (self, event, target, player, data)
    local use, dat = player.room:askToUseActiveSkill(player, {
      skill_name = wuyulong.name,
      prompt = "#lingling__wuyulong",
      skip = true,
    })
    if use and dat then
      event:setCostData(self, { from = player, tos = dat.targets})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local effect = table.simpleClone(event:getCostData(self))
    --effect.from = player
    spec.on_use(self, room, effect)
  end,
})

return wuyulong
